package com.appkubes.mall.restful.application.article.controller;

import com.appkubes.common.Response;
import com.appkubes.mall.core.entity.MallSystemConfig;
import com.appkubes.mall.restful.application.article.service.impl.ArticleServiceImpl;
import com.appkubes.mall.restful.application.article.vo.ArticleVo;
import com.appkubes.mall.restful.application.common.base.BaseController;
import com.appkubes.mall.restful.application.system.config.service.impl.ConfigServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api("文章模块")
@RestController
@RequestMapping("/article")
public class ArticleController extends BaseController {


    @Autowired
    ArticleServiceImpl articleServiceImpl;

    @Autowired
    ConfigServiceImpl configServiceImpl;

    @ApiOperation(value = "获取文章详情")
    @PostMapping("/getArticle")
    public Object getArticle(
            @RequestBody ArticleVo articleVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return Response.error("参数错误");
        }
        Map<String,Object> response = new HashMap<>();
        if("13".equals(articleVo.getArticleKey())){
            //团长协议,配置文件获取
            MallSystemConfig config = configServiceImpl.getByKey("leader_apply_detail");
            response.put("content",config.getConfigValue());
            return imgResponse(response);
        }
        if("14".equals(articleVo.getArticleKey())){
            //配送协议,配置文件获取
            MallSystemConfig config = configServiceImpl.getByKey("clerk_apply_detail");
            response.put("content",config.getConfigValue());
            return imgResponse(response);
        }
        if("15".equals(articleVo.getArticleKey())){
            //配送帮助文档
            MallSystemConfig config = configServiceImpl.getByKey("clerk_apply_help");
            response.put("content",config.getConfigValue());
            return imgResponse(response);
        }
        return imgResponse(articleServiceImpl.getById(articleVo.getArticleKey()));
    }

}
